<template>
        <view class="background" style="position: relative; left: 43rpx; top: 61rpx">
            <image class="detailsImg" :src=searchResult[0].pic>
            <text class="detailsName" style="color: red;">{{searchResult[0].name}}</text>
            <button class="detailsForm" @click="detailsSports">运动卡路里消耗</button>
			<view class="detailsData">
                运动
                <input class="inputData" type="number" placeholder="请输入数字" maxlength="8"  @input="setTime" />
                分钟
            </view>
            <button class="cardButton"  @tap="addTodayCard">添加到今日运动打卡</button>
        </view>
</template>

<script>
// pages/health/sports/details/details.js
export default {
    data() {
        return {
			sportsTime:0,
			searchResult:[],
			searchId:0,
		};
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
		this.searchId=options.id
		var urlstr = 'exerciseInfo/get/id=' + this.searchId
		this.$https({
			url: this.$baseUrl + urlstr,
			success: (res) => {
				if (res.statusCode == 200) {
						this.searchResult.push({
							'category': res.data['data'].category,
							'id': res.data['data'].id,
							'name': res.data['data'].name,
							'pic': res.data['data'].pic,
							'state': res.data['data'].state,
							'ratio': res.data['data'].ratio,
							'version': res.data['data'].version,
					})
				} else {
					uni.showToast({
						title: res.data.errorCode,
						icon: 'error',
					})
				}
			},
		
			fail: (e) => {
				console.log(e)
				uni.showToast({
					title: '搜索失败',
					icon: 'error',
				})
			}
		});
	},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        addTodayCard: function () {
			var num = 1;
			var time=this.sportsTime;
        	var pages=getCurrentPages();
        	var indexUrl='pages/health/sports/clockIn/clockIn';
        	var delta=1;
        	for(var i=1;i<pages.length;i++)
        	{
        		if(indexUrl==pages[pages.length-i].route)
        		{
        			delta=i-1
        		}
        	};
			if(time==0)
			{
				uni.showToast({
					title: '时间不能为0',
					icon: 'error',
				})
				return
			}
			getApp().globalData.sportsTime=time
			getApp().globalData.sportsName=this.searchResult[0].name
			getApp().globalData.sportsId=this.searchId
			getApp().globalData.sportsNum=num
			if(delta!=1)
			{
				uni.navigateBack({
					delta:delta
				});
			}
			else
			{
				uni.navigateTo({
					url:"/pages/health/sports/clockIn/clockIn"
				})
			}
        },
		setTime:function(e){
			this.sportsTime=e.detail.value
			console.log(this.sportsTime)
		},
		detailsSports: function(){
			uni.navigateTo({
				url:"/pages/health/sports/details/composition/composition?id="+this.searchId
			})
		}
    }
};
</script>
<style>
@import './details.css';
</style>
